#pragma once

#include <QPointF>
#include <QPair>
#include <QSharedPointer>
#include <QGraphicsView>
#include <QGraphicsPixmapItem>
#include <QTimeLine>

class DynamicObject
{
public:
    enum CardinalDirection
    {
        eNorth = 0,
        eSouth,
        eEast,
        eWest
    };

    struct Position
    {
        Position(int i_x = 0, int i_y = 0) : x(i_x), y(i_y) {}
        int x;
        int y;

        bool operator==(const Position& cmp)
        {
            return ( (x == cmp.x) && (y == cmp.y) );
        }
    };

    DynamicObject();

    virtual unsigned width() const  = 0;
    virtual unsigned height() const = 0;

    void SetSpeed(int speed);
    inline int Speed() const { return m_speed; }

    inline Position CurrentPosition() const { return m_pos;}
    inline void SetPosition(Position pos) { m_pos = pos; }

    inline CardinalDirection Direction() const { return m_direction;}
    inline void SetDirection(CardinalDirection direction) { m_direction = direction; }

    inline unsigned Progress() const {return m_completeness;}
    inline void SetProgress(unsigned progress) { m_completeness = progress; }

    inline QPointF ImagePosition() const { return m_texture->pos(); }
    inline void SetImagePosition(const QPointF pos) { m_texture->setPos(pos); }

    inline qreal ImageRotation() const { return m_texture->rotation(); }
    inline void SetImageRotation(const qreal angle) {m_texture->setRotation(angle);}

    void UpdateImagePosition();

    void move();
    inline void moveFor(unsigned times)
    {
        for(unsigned i=0;i<times;++i)
        {
            move();
        }
    }

    virtual void destroy() = 0;

protected:
    Position m_pos;
    CardinalDirection m_direction;
    int m_speed;
    unsigned m_completeness;
    QSharedPointer<QGraphicsPixmapItem> m_texture;
    QSharedPointer<QGraphicsView>  m_view;
    QSharedPointer<QGraphicsScene> m_scene;
};

